<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use App\Utils\Other\Router\Router;
use App\Controller\Publics\V2 as PublicsV2;

Router::addGroup('/safepay/', function () {
    Router::addGroup('v2/', function () {
        Router::addGroup('shop', function () {
            Router::post('', [\App\Controller\Safepay\V2\Shop\Shop::class, 'save']);
            Router::post('/update', [\App\Controller\Safepay\V2\Shop\Shop::class, 'update']);
        });
        Router::addGroup('order', function () {
            Router::post('/delivery', [\App\Controller\Safepay\V2\Orders\Order::class, 'delivery']);
        });
    });
});

/** API */
Router::addGroup('/api/', function (){
    Router::addGroup('v2/', function (){
        Router::addGroup('good', function () {
            Router::get('/read', [\App\Controller\Api\V2\Goods\Good::class, 'read']);
            Router::post('/status', [\App\Controller\Api\V2\Goods\Good::class, 'status']);
            Router::post('/destroy', [\App\Controller\Api\V2\Goods\Good::class, 'destroy']);
            Router::resource('', \App\Controller\Api\V2\Goods\Good::class);
        });
        Router::addGroup('order', function () {
            Router::get('/read', [\App\Controller\Api\V2\Orders\Order::class, 'read']);
            Router::post('/refund', [\App\Controller\Api\V2\Orders\Order::class, 'refund']);
            Router::post('/logistic', [\App\Controller\Api\V2\Orders\Order::class, 'logistics']);
            Router::resource('', \App\Controller\Api\V2\Orders\Order::class);
        });
    });
},['middleware' => [
    \App\Middleware\Api\CheckSignMiddleware::class
]]);

Router::addGroup('/mini/', function () {
    Router::addGroup('v2/', function () {
        Router::post('oauth2', [\App\Controller\Mini\V2\Publics\Login::class, 'oauth2']);
        Router::addGroup('', function () {
            Router::addGroup('payer', function () {
                Router::post('/code', [\App\Controller\Mini\V2\Users\Payer::class, 'code']);
                Router::resource('', \App\Controller\Mini\V2\Users\Payer::class);
            });
            Router::addGroup('payment', function () {
                Router::post('', [\App\Controller\Mini\V2\Payment\Payment::class, 'save']);
            });
            Router::addGroup('order', function () {
                Router::get('/read', [\App\Controller\Mini\V2\Orders\Order::class, 'read']);
            });
        }, [
            'middleware' => [
                \App\Middleware\Authorization::class
            ]
        ]);
    });
});

Router::addGroup('/publics/', function () {
    Router::addGroup('v1/', function () {
        Router::addGroup('payment', function () {
            Router::addGroup('/notify/', function () {
                Router::post('safepayMini', [PublicsV2\Payment\Notify::class, 'safepayMini']);
            });
        });
        Router::addGroup('orders', function () {
            Router::post('/no179', [PublicsV2\Orders\Declaration::class, 'save']);
        });
    });
});

/** 管理员 */
Router::addGroup('/admin/', function (){
    Router::addGroup('v1/', function (){
        Router::addGroup('login', function (){
            Router::get('/code', [\App\Controller\Admin\V1\Publics\Login::class, 'code']);
            Router::post('', [\App\Controller\Admin\V1\Publics\Login::class, 'save']);
        });
        Router::addGroup('', function (){
            Router::get('index', [\App\Controller\Admin\V1\Publics\Index::class, 'index']);
            // 管理员相关
            Router::addGroup('admin', function (){
                Router::resource('', \App\Controller\Admin\V1\Admin\Admin::class);
                Router::resource('/log', \App\Controller\Admin\V1\Admin\AdminLog::class);
                Router::resource('/menu', \App\Controller\Admin\V1\Admin\Menu::class, [], [
                    'sort' => ['type' => 'put','path' => '/sort/{id}']
                ]);
                Router::resource('/permission', \App\Controller\Admin\V1\Admin\Permission::class);
                Router::resource('/role', \App\Controller\Admin\V1\Admin\Role::class);
            });
            // 工具相关
            Router::addGroup('tools', function (){
                Router::addGroup('/uploadify', function (){
                    Router::post('/images', [\App\Controller\Admin\V1\Publics\Uploadify::class, 'images']);
                    Router::post('/image', [\App\Controller\Admin\V1\Publics\Uploadify::class, 'image']);
                    Router::delete('/images', [\App\Controller\Admin\V1\Publics\Uploadify::class, 'destroy']);
                });
            });
            // 订单相关
            Router::addGroup('order', function () {
                Router::get('/export', [\App\Controller\Admin\V1\Order\Order::class, 'export']);
                Router::put('/declares/{id}', [\App\Controller\Admin\V1\Order\Order::class, 'declares']);
                Router::put('/erp/{id}', [\App\Controller\Admin\V1\Order\Order::class, 'erp']);
                Router::put('/notify/{id}', [\App\Controller\Admin\V1\Order\Order::class, 'notify']);
                Router::resource('', \App\Controller\Admin\V1\Order\Order::class);
            });
            Router::addGroup('shop', function () {
                Router::resource('', \App\Controller\Admin\V1\Shop\Shop::class);
            });
            Router::delete('logout', [\App\Controller\Admin\V1\Publics\Login::class, 'destroy']);
        }, ['middleware' => [
            \App\Middleware\Authorization::class,
            \App\Middleware\PermissionMiddleware::class
        ]]);
    });
});

Router::post('/ciq/customs/platDataOpenQnl179', [PublicsV2\Orders\Declaration::class, 'save']);

